﻿@using Nop.Core.Domain.Common
@using Logistics.Web.Models.Shipment
@model ChangeAddressModel

<div class="address-select-wrapper">
    <div class="section-wrapper">
        @if (Model.Disallowed || Model.IsPaymentRequired)
        {
            <p>You are unable to modify this package's address.</p>
            <input type="button" value="Back to Package" class="btn btn-normal shipment-action-back-button" />
        }
        else if (Model.Success)
        {
            <p>Address is successfully modified for this package.</p>
            <input type="button" value="Back to Package" class="btn btn-normal shipment-action-back-button" />
        }
        @*else if (Model.IsPaymentRequired)
        {
            using (Html.BeginForm("ChangeAddress", "Shipment"))
            { 
                <p>You will be charged for a service fee for modifying this address. Do you wish to continue?</p>
                <input type="button" value="Yes" class="btn btn-danger" data-action="submit" data-name="@Html.NameFor(model => model.IsPaymentRequired)" data-value="true" />
                <input type="button" value="No, Back to Package" class="btn btn-normal shipment-action-back-button" />
                @Html.HiddenFor(model => model.SelectedAddressId)
                @Html.HiddenFor(model => model.PackageId)
                @Html.HiddenFor(model => model.TypeId)
            }
        }*@
        else
        {
            using (Html.BeginForm("ChangeAddress", "Shipment", new { packageId = Model.PackageId, typeId = Model.TypeId }, FormMethod.Post, new { id = "change-address-form", Class = "change-address-slides" }))
            {
                <div class="address-form slide">
                    <h1>@T("Logistics.Order.ChangeAddress", Model.AddressTypeStr)</h1>
                    @if (Model.Addresses != null && Model.Addresses.Count > 0)
                    {
                        <input type="button" class="address-select btn btn-normal" value="Select from Saved Addresses" />
                    }
                    @Html.RequiredHint()<span>= Mandatory fields</span>
                    <div class="row">
                        
                        <div class="location-group">
                            <div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
                                @Html.RequiredHint() @Html.LabelFor(model => model.Address.FirstName)
                                @Html.TextBoxFor(model => model.Address.FirstName, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Address.FirstName)
                            </div>

                            <div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
                                @Html.RequiredHint() @Html.LabelFor(model => model.Address.LastName)
                                @Html.TextBoxFor(model => model.Address.LastName, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Address.LastName)
                            </div>
                        </div>

                        <div class="location-group my-location-company col-ms-12 col-xs-12 col-sm-12 col-md-12 col-lg-12">
                            @Html.LabelFor(model => model.Address.Company)
                            @Html.TextBoxFor(model => model.Address.Company, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.Address.Company)
                        </div>


                        <div class="location-group col-ms-12 col-xs-12 col-sm-9 col-md-9 col-lg-9">
                            @Html.RequiredHint() @Html.LabelFor(model => model.Address.Address1)
                            @Html.TextBoxFor(model => model.Address.Address1, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.Address.Address1)
                        </div>
                        <div class="location-group col-ms-12 col-xs-12 col-sm-3 col-md-3 col-lg-3">
                            @Html.LabelFor(model => model.Address.Address2)
                            @Html.TextBoxFor(model => model.Address.Address2, new { @class = "form-control", placeholder = T("Address.Fields.Address2.Placeholder").Text })
                            @Html.ValidationMessageFor(model => model.Address.Address2)
                        </div>

                        <div class="location-group">
                            <div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
                                @Html.RequiredHint() @Html.LabelFor(model => model.Address.City)
                                @Html.TextBoxFor(model => model.Address.City, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Address.City)
                            </div>
                            <div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
                                @Html.RequiredHint() @Html.LabelFor(model => model.Address.StateProvinceId)
                                @Html.DropDownListFor(model => model.Address.StateProvinceId, Model.AvailableStateProvinces, new { @class = "form-control" })
                            </div>
                        </div>
                        <div class="location-group">
                            <div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
                                @Html.LabelFor(model => model.Address.CountryName)
                                <div class="location-display">
                                    @Html.TextBoxFor(model => model.Address.CountryName, new { @class = "form-control", disabled = "disabled" })
                                    @Html.HiddenFor(model => model.Address.CountryId)
                                </div>
                            </div>
                            <div class="col-ms-12 col-xs-12 col-sm-6 col-md-6 col-lg-6">
                                @Html.RequiredHint() @Html.LabelFor(model => model.Address.ZipPostalCode)
                                @Html.TextBoxFor(model => model.Address.ZipPostalCode, new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Address.ZipPostalCode)
                            </div>
                        </div>
                        <div class="location-group">
                            <div class="location-group col-ms-12 col-xs-12 col-sm-4 col-md-4 col-lg-4">
                                @Html.LabelFor(model => model.Address.Email)
                                @Html.TextBoxFor(model => model.Address.Email, new { @class = "form-control" })
                            </div>
                            <div class="col-ms-12 col-xs-12 col-sm-4 col-md-4 col-lg-4">
                                @Html.RequiredHint() @Html.LabelFor(model => model.Address.CellPhoneNumber)
                                @Html.TextBoxFor(model => model.Address.CellPhoneNumber, new { placeholder = T("Address.Fields.CellPhoneNumber.Placeholder").Text, @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Address.CellPhoneNumber)
                            </div>
                            <div class="col-ms-12 col-xs-12 col-sm-4 col-md-4 col-lg-4">
                                @Html.LabelFor(model => model.Address.PhoneNumber)
                                @Html.TextBoxFor(model => model.Address.PhoneNumber, new { placeholder = T("Address.Fields.PhoneNumber.Placeholder").Text, @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.Address.PhoneNumber)
                            </div>
                        </div>
                        <div class="location-group col-ms-12 col-xs-12 col-sm-12 col-md-12 col-lg-12">
                            <div class="address-type-wrapper">
                                <table>
                                    <tbody>
                                        @if (Model.IsAddressTypeVerified)
                                        {
                                            <tr>
                                                <td>
                                                    <label>This is a </label>
                                                    @Html.HiddenFor(model => model.Address.Type)
                                                    @Html.HiddenFor(model => model.IsAddressTypeVerified)
                                                </td>
                                                <td><span class="lowercase">@Model.Address.Type.Value</span> location</td>
                                            </tr>
                                        }
                                        else
                                        {
                                            <tr>
                                                <td>
                                                    <label>@Html.RequiredHint() This is a </label>
                                                </td>
                                                <td>@Html.RadioButtonFor(model => model.Address.Type, AddressType.Business)</td>
                                                <td>business location</td>
                                            </tr>
                                            <tr>
                                                <td></td>
                                                <td>@Html.RadioButtonFor(model => model.Address.Type, AddressType.Residential)</td>
                                                <td>residential location</td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                                @Html.HiddenFor(model => model.Address.IsTypeRequired)
                            </div>
                            @Html.ValidationMessageFor(model => model.Address.Type)
                        </div>
                        <div class="clear"></div>
                    </div>
                    <input type="button" class="btn btn-normal" data-action="submit" data-name="@Html.NameFor(model => model.Address.Id)" data-value="@Html.ValueFor(model => model.Address.Id)" value="@T("Common.Save")" />
                    <input type="button" class="btn btn-normal" data-action="cancel" value="@T("Common.Cancel")" />
                    <div class="clear"></div>
                </div>
                if (Model.Addresses != null && Model.Addresses.Count > 0)
                {
                    <div class="address-select-list slide">
                        <h2>Select Address</h2>
                        @foreach (var address in Model.Addresses)
                        {
                            <div class="address-select-item" data-action="submit" data-name="@Html.NameFor(model => model.SelectedAddressId)" data-value="@address.Value" data-name2="selectAddress" data-value2="true">
                                <div class="address-select-item-content">
                                    @Html.Raw(address.Text)
                                </div>
                            </div>
                        }
                        <div class="clear"></div>
                        <div class="buttons">
                            <input type="button" class="address-select-cancel btn btn-normal" value="@T("Common.Cancel")" />
                        </div>
                    </div>
                }
            }
        }
    </div>
</div>